package com.zkdcloud.util;

import com.zkdcloud.constant.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;

/**
 * 加载配置文件
 *
 * @author zk
 * @date 2018-02-23 14:17
 */
public class PropertiesUtils {
    private static Logger logger = LoggerFactory.getLogger(PropertiesUtils.class);

    public static final Properties properties = new Properties();

    static {
        try {
            File file = new File(Thread.currentThread().getContextClassLoader().getResource(Constants.PROPERTIES.INIT_PROPERTIES).getPath());
            properties.load(new FileReader(file));
        } catch (IOException e) {
            throw new IllegalStateException("can't find init properties");
        }
    }

    /**
     * 根据key 获取String value
     *
     * @param key key
     * @return String
     */
    public static String getString(String key){
        return properties.getProperty(key);
    }
}
